package com.insurance.web;

import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import com.insurance.bean.Agent;
import com.insurance.bean.Blog;
import com.insurance.service.BlogService;
import org.apache.struts2.ServletActionContext;

public class BlogAction {
	@Resource BlogService blogService;
	private List<Blog> blogs;
	private Blog blog;
	private Integer id;
	

	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public Blog getBlog() {
		return blog;
	}
	public void setBlog(Blog blog) {
		this.blog = blog;
	}
	
	/**
	 * ��־��ʾ
	 */
	public String list(){
		this.blogs = this.blogService.getBlogs();
		return "list";
	}
	/**
	 * ��־��ʾ
	 */
	public String alist(){
		Agent agent = (Agent)ServletActionContext.getRequest().getSession().getAttribute("agent");
		this.blogs = this.blogService.getBlogsByWriter(agent.getName());
		return "alist";
	}
	/**
	 * ��ƪ��־
	 */
	public String show(){
		this.blog = this.blogService.getBlog(this.id);
		return "show";
	}	
	
	/**
	 * ������־����
	 */
	public String addUI(){
		return "add";
	}
	
	/**
	 * ������־
	 */
	public String add(){
		blog.setBlogTime(new Date()); 
		Agent agent = (Agent)ServletActionContext.getRequest().getSession().getAttribute("agent");
		blog.setWriter(agent.getName());
		this.blogService.save(this.blog);
		return "success";
	}
	
	/**
	 * �޸���־����
	 */
	public String modifyUI(){
		this.blog = this.blogService.getBlog(this.id);
		return "modify";
	}
	
	/**
	 * �޸���־
	 */
	public String modify(){
		this.blogService.update(this.blog);
		return "success";
	}
	
	/**
	 * ɾ����־
	 */
	public String del(){
		this.blogService.delete(this.id);
		return "success";
	}
	
	
	public List<Blog> getBlogs() {
		return blogs;
	}

	public void setBlogs(List<Blog> blogs) {
		this.blogs = blogs;
	}

	
}
